package mspbots.hubspot.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;

/**
 * mspbots.data.autotask.utils.FilterExpression
 * {
 * "op": "eq",
 * "field": "IsActive",
 * "value": true
 * },
 * {
 * "op": "or",
 * "items": [
 * {
 * "op": "eq",
 * "field": "lastname",
 * "value": "Smith"
 * },
 * {
 * "op": "eq",
 * "field": "lastname",
 * "value": "Jones"
 * },
 * {
 * "op": "and",
 * "items": [
 * {
 * "op": "eq",
 * "field": "firstname",
 * "value": "Chris"
 * },
 * {
 * "op": "eq",
 * "field": "lastname",
 * "value": "Brady"
 * }
 * ]
 * }
 * ]
 * }
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/7/10
 */
@Data
@NoArgsConstructor
@ApiModel("Auto task api query filter expression model")
public class FilterExpression {

    /**
     * Operator     Definition <br>
     * EQ:	        Requires that the field value match the exact criteria provided <br>
     * NOTEQ	    Requires that the field value be anything other than the criteria provided <br>
     * GT/GTE	    Requires that the field value be greater than or equal to the criteria provided <br>
     * LT/LTE	    Requires that the field value be less than or equal to the criteria provided <br>
     * BEGINSWITH	Requires that the field value begin with the defined criteria <br>
     * ENDSWITH 	Requires that the field value end with the defined criteria <br>
     * CONTAINS	    Allows for the string provided as criteria to match any resource that contains the string in its value <br>
     * EXIST	    Enter exist to query for fields in which the data you specify is not null. <br>
     * NOTEXIST     Enter notExist to query for fields in which the specified data is null. <br>
     * IN	        With this value specified, the query will return only the values in the list array that match the field value you specify. <br>
     * NOTIN	    With this value specified, the query will only return the values in the list array that do not match the field value you specify. <br>
     */
    @NotBlank(message = "Filter operators  [op] can not empty," +
            "value is [eq,noteq,gt/gte,lt/lte,beginsWith,endsWith,contains,exist,notExist,in,notIn]")
    @ApiModelProperty(example = "GTE")
    private String operator;

    @NotBlank(message = "Filter operators  [field] can not empty,")
    @ApiModelProperty(example = "id")
    private String propertyName;

    @NotBlank(message = "Filter operators  [value] can not empty,")
    @ApiModelProperty(example = "0")
    private String value;

    @Builder
    public FilterExpression(String operator, String propertyName, String value) {
        this.operator = operator;
        this.propertyName = propertyName;
        this.value = value;
    }

    public static FilterExpression withDefault() {
        return FilterExpression.builder().operator("GTE").value("0").propertyName("id").build();
    }

}
